package cn.single;

/**
 * @author oldliu
 * @since 1.0
 */
public class Sun {
    //private static Sun sun=new Sun();
    private static Sun sun;

    private Sun() {
        System.out.println("sun is new");
    }
    public  static Sun getInstance(){
        return SingleHolder.sun;
    }

    //    public  static Sun getInstance() {
//        if (sun == null) {
//            synchronized (Sun.class) {
//                if (sun == null) {
//                    sun = new Sun();
//                }
//            }
//
//        }
//        return sun;
//    }
 private static final class SingleHolder{
        private  static final Sun sun=new Sun();
}

//    public  static Sun getInstance(){
//        if(sun==null){
//            try {
//                Thread.sleep(40);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            sun=new Sun();
//        }
//        return sun;
//    }
}
